package com.hbfu.zggdwlzzsx.controller;

import com.hbfu.zggdwlzzsx.entity.Works;
import com.hbfu.zggdwlzzsx.service.WorkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/work")
@CrossOrigin
public class WorkController {

    @Autowired
    private WorkService workService;
//    接收所有work
 /*   @GetMapping()
    public List<Works> getAllWork(){
        return workService.list();
    }*/

    //根据id查询详细信息
    @GetMapping("/{workid}")
    public Works getWorkById(@PathVariable Integer workid){
        return workService.getWorkById(workid);
    }


    @GetMapping
    public List<Works> getWorks(@RequestParam(required = false) String name, @RequestParam(required = false) Integer categoryId) {
        return workService.getWorks(name, categoryId);
    }


    @PostMapping
    public boolean addWork(@RequestBody Works works) {
        return workService.save(works);
    }


}
